// 桑基图
<template>
  <div class="threeBarChart" id="sankey"></div>
</template>

<script>
export default {
  name: '',
  data() {
    return {}
  },
  computed: {
    reset() {
      return this.$store.getters.sidebar.opened
    }
  },
  props: {
    xline: Array, // x轴名称列表
    yline: Array, // y轴数据
    config: Object // 参数配置
  },

  methods: {
    // 重新绘制图表
    forceRerender() {

    },
    setChart() {

      this.myChart = this.$echarts.init(document.getElementById('sankey'))
      this.myChart.clear();
      this.myChart.resize()
      this.myChart.setOption(this.option);
    }
  },
  data() {
    return {
      show: true,
      myChart: undefined,
      option: {
        series: {
          type: 'sankey',
          layout: 'none',
          levels: [
            {
              depth: 0,
              itemStyle: {
                color: '#fbb4ae'
              },
              lineStyle: {
                color: 'source',
                opacity: 0.6
              }
            },
            {
              depth: 1,
              itemStyle: {
                color: '#b3cde3'
              },
              lineStyle: {
                color: 'source',
                opacity: 0.6
              }
            },
            {
              depth: 2,
              itemStyle: {
                color: '#ccebc5'
              },
              lineStyle: {
                color: 'source',
                opacity: 0.6
              }
            },
            {
              depth: 3,
              itemStyle: {
                color: '#decbe4'
              },
              lineStyle: {
                color: 'source',
                opacity: 0.6
              }
            }
          ],
          emphasis: {
            focus: 'adjacency'
          },
          data: [
            {
              name: '直接排放'
            },
            {
              name: '能源间接排放'
            },
            {
              name: '无烟煤'
            },
            {
              name: '柴油'
            },
            {
              name: 'CO2'
            },
            {
              name: 'CH4'
            },
            {
              name: 'N2O'
            },
            {
              name: 'HFC5'
            },
            {
              name: 'PFC5'
            },
            {
              name: 'SF6'
            },

          ],
          links: [
            {
              source: '直接排放',
              target: '无烟煤',
              value: 3337754.78
            },
            {
              source: '直接排放',
              target: '柴油',
              value: 3337754.78
            },
            {
              source: '能源间接排放',
              target: '无烟煤',
              value: 3337754.78
            },
            {
              source: '能源间接排放',
              target: '柴油',
              value: 3337754.78
            },
            {
              source: '无烟煤',
              target: 'CO2',
              value: 3337754.78
            },
            {
              source: '无烟煤',
              target: 'CH4',
              value: 3337754.78
            },
            {
              source: '无烟煤',
              target: 'N2O',
              value: 3337754.78
            },
            {
              source: '无烟煤',
              target: 'HFC5',
              value: 3337754.78
            },
            {
              source: '柴油',
              target: 'PFC5',
              value: 3337754.78
            },
            {
              source: '柴油',
              target: 'SF6',
              value: 3337754.78
            },
            {
              source: '柴油',
              target: 'CO2',
              value: 3337754.78
            },
          ]
        },
      }
    }
  },
  mounted() {
    this.setChart()
  },
  watch: {
    reset() {
      this.forceRerender()
    }
  }
}
</script>

<style lang="less" scoped>
.threeBarChart {
  height: 100%;
  width: 100%;
}
</style>
